package com.example.server.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.server.bean.MenuRole;
import com.example.server.util.RespBean;
import com.example.server.dao.MenuRoleDao;
import com.example.server.service.IMenuRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 别怿言
 * @since 2023-02-03
 */
@Service
@Transactional
public class MenuRoleServiceImpl extends ServiceImpl<MenuRoleDao, MenuRole> implements IMenuRoleService {

    @Autowired
    private MenuRoleDao menuRoleDao;

    @Override
    @Transactional
    public RespBean updateMenuRole(Integer rid, Integer[] mids) {
        menuRoleDao.delete(new QueryWrapper<MenuRole>().eq("rid",rid));
        if(null== mids || mids.length == 0){
            return RespBean.success("更新角色菜单成功！");
        }
        if(menuRoleDao.insertNewMenu(rid,mids)==mids.length){
            return RespBean.success("更新角色菜单成功！");
        }
        return RespBean.error("更新角色菜单失败！");
    }
}
